package com.example.myandroidtest.ui.video;

import android.media.MediaCas;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.os.Bundle;
import android.view.Surface;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myandroidtest.databinding.ActivityVideoBinding;

import java.io.IOException;
import java.nio.ByteBuffer;

public class VideoActivity extends AppCompatActivity {

    ActivityVideoBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityVideoBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        //摄像头捕获的数据  yuv->h264
        //麦克风捕获的数据  pcm->AAC  ->MP4

        //视频格式mp4 avi rmvn flv
        //什么是封装格式 什么是解封装

        //ffmpeg  摄像头捕获的数据编码  yuv->h264

        // 1. 宏块方式编码 h261 
        // 2. 参考帧编码
        //

        MediaFormat format = new MediaFormat();
        Surface surface = null;

        MediaExtractor mediaExtractor = new MediaExtractor();
        mediaExtractor.selectTrack(1);
        mediaExtractor.seekTo(100, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(100 * 1000);
        try {
            //dsp芯片创建一个解码器
            MediaCodec mediaCodec = MediaCodec.createDecoderByType("");
            mediaCodec.configure(format, surface, null, 0);

            while (true) {
                int dequeueInputIndex = mediaCodec.dequeueInputBuffer(1000);
                if (dequeueInputIndex >= 0) {
                    long sampleTime = mediaExtractor.getSampleTime();
                } else if (false) {
                    mediaExtractor.advance();
                    continue;
                }
            }

//            int i = mediaExtractor.readSampleData(byteBuffer, 0);

        } catch (IOException e) {
        }


//        MediaFormat format

    }
}